﻿#region Using

using GameCommon.Args;
using GameCommon.Components;
using GameCommon.Manager;

#endregion

namespace GameGraphics.Screens
{
    public class CameraManager
    {
        private readonly Camera camera;

        private readonly int cameraMoveArea;

        private readonly int cameraMovement;

        public CameraManager(Camera camera, int cameraMovement, int cameraMoveArea)
        {
            this.camera = camera;
            this.cameraMovement = cameraMovement;
            this.cameraMoveArea = cameraMoveArea;
        }

        public void UpdateCamera()
        {
            var pos = Managers.MouseManager.MousePosition;

            if (pos.X > this.camera.ScreenSize.Width || pos.Y > this.camera.ScreenSize.Height)
            {
                return;
            }

            if (pos.X < this.cameraMoveArea)
            {
                this.camera.X -= this.cameraMovement;
            }

            if (pos.X > this.camera.ScreenSize.Width - this.cameraMoveArea)
            {
                this.camera.X += this.cameraMovement;
            }

            if (pos.Y < this.cameraMoveArea)
            {
                this.camera.Y -= this.cameraMovement;
            }

            if (pos.Y > this.camera.ScreenSize.Height - this.cameraMoveArea)
            {
                this.camera.Y += this.cameraMovement;
            }

            this.camera.UpdateMatrix();
        }
    }
}